/**
 * FileName: MinStack
 * Author:   powersi
 * Date:     2021/2/7 20:11
 * Description: 1
 */
package com.zm.demo.core.leetcode.backtracking;

import java.util.ArrayList;
import java.util.List;
import java.util.Stack;

/**
 * 5 3 3 3 8 7 2 1
 * 5 3 3 3 3 3 2 1
 * Description: 1
 * Author:      powersi
 * Date:        2021/2/7 20:11
 */
class MinStack {

    Integer min = Integer.MAX_VALUE;
    Stack<Integer> stack  = new Stack<Integer>();
    Stack<Integer> minStack  = new Stack<Integer>();
    /** initialize your data structure here. */
    public MinStack() {

    }

    public void push(int x) {
        stack.push(x);
        min = Math.min(min, x);
        minStack.push(min);
    }

    public void pop() {
        stack.pop();
        minStack.pop();
        if (minStack.size() == 0){
            min = Integer.MAX_VALUE;
        }
    }

    public int top() {
        return stack.peek();
    }

    public int min() {
        return minStack.peek();
    }
}